package top.forgirl.service;

import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import top.forgirl.result.Result;
import top.forgirl.result.ResultEnum;

@Service("iTestService")
//@FeignClient(value = "forgirl-test-service", fallbackFactory = TestServiceFallbackImpl.class)
@FeignClient(value = "forgirl-test-service", fallback =Fallback.class)
public interface ITestService {

    @GetMapping("/test/hello")
    Result<String> sayHello();
}

class TestServiceFallbackImpl implements FallbackFactory<ITestService> {

    @Override
    public ITestService create(Throwable cause) {
        return new ITestService() {
            @Override
            public Result<String> sayHello() {
                return universalMethod();
            }
        };
    }

    protected Result<String> universalMethod() {
        return new Result<>(ResultEnum.FAILED, "服务器繁忙，请稍后再试~");
    }
}

class Fallback implements ITestService {

    @Override
    public Result<String> sayHello() {
        return new Result<>(ResultEnum.FAILED, "服务器繁忙，请稍后再试~");
    }
}